package Common;

import java.util.EnumSet;

import Model.Cell;

public class DirectionMethods {
	public static EnumSet<Direction> GetPossibleDirectionsForSolutionPath(Cell[][] cellField, Cell cell)
	{
		EnumSet<Direction> possibleDirection = cell.Walls.clone();
		
		if(possibleDirection.contains(Direction.TOP))
		{
			if(cell.Y == 0 
			 ||
			   (cellField[cell.X][cell.Y - 1] == null)
			    || cellField[cell.X][cell.Y - 1].VisidtedWhileGeneration)
			{
				possibleDirection.remove(Direction.TOP);
			}
		}
		
		if(possibleDirection.contains(Direction.LEFT))
		{
			if(cell.X == 0 
			 ||
			   (cellField[cell.X - 1][cell.Y] == null)
			    || cellField[cell.X - 1][cell.Y].VisidtedWhileGeneration)
			{
				possibleDirection.remove(Direction.LEFT);
			}
		}
		
		if(possibleDirection.contains(Direction.RIGHT))
		{
			if(cell.X == cellField.length - 1
			 ||
			   (cellField[cell.X + 1][cell.Y] == null)
			    || cellField[cell.X + 1][cell.Y].VisidtedWhileGeneration)
			{
				possibleDirection.remove(Direction.RIGHT);
			}
		}
		
		if(possibleDirection.contains(Direction.BOTTOM))
		{
			if(cell.Y == cellField[cell.X].length - 1
			 ||
			   (cellField[cell.X][cell.Y + 1] == null)
			    || cellField[cell.X][cell.Y + 1].VisidtedWhileGeneration)
			{
				possibleDirection.remove(Direction.BOTTOM);
			}
		}
			
		
		return possibleDirection;
	}
	
	public static int CountDirections(EnumSet<Direction> direction)
	{
		int cnt = 0;
		for (Direction d : Direction.values()) {
			if(direction.contains(d))
			{
				cnt++;
			}
		}
		return cnt;
	}
	
}
